/**
 * Created by jerome.arnoult on 15/05/14.
 */
function gamestructure(id, usage, resourcesToBuild, production, capacity, life){
    this.id = id;
    this.underConstruct = (resourcesToBuild == null) ? false : true;
    this.resourcesToBuild = {};
    this.resourcesStorage = {};
    this.usage = usage;
    this.production = production;
    this.capacity = capacity;
    this.life = life;

    this.graphics = {};
}
gamestructure.prototype.place = function(x, y, orientation, options){
    //console.log([x,y]);
    var coords = game.gameMap.convertGridCoordsToPlacementCoords([x,y]);
    switch(this.usage){
        // THORIUM
        case "thorium":
            this.graphics = game.gameRenderer.createResourceCloud(coords[0], coords[1], options.size);
            switch(options.size){
                case "tiny"://1X1
                    var ASCoords = game.gameMap.convertGridCoordsToAStarCoords([x,y]);
                    game.gameMap.grid.pathGrid[ASCoords[0]][ASCoords[1]] = 1;
                    break;

                case "medium"://3X3
                    var ASCoords = game.gameMap.convertGridCoordsToAStarCoords([x - 1,y]);
                    for(var row=0;row<3;row++){
                        for(col=0;col<3;col++){
                            var astarX = (ASCoords[0]>>0) + col + row;
                            var astarY = (ASCoords[1]>>0) - row + col;
                            game.gameMap.grid.pathGrid[astarX][astarY] = 1;
                        }
                    }
                    break;

                case "large"://5X5
                    var ASCoords = game.gameMap.convertGridCoordsToAStarCoords([x - 2,y]);
                    for(var row=0;row<5;row++){
                        for(col=0;col<5;col++){
                            var astarX = (ASCoords[0]>>0) + col + row;
                            var astarY = (ASCoords[1]>>0) - row + col;
                            game.gameMap.grid.pathGrid[astarX][astarY] = 1;
                        }
                    }
                    break;
            }
            break;

        // SPAWN
        case "spawn":
            this.graphics = game.gameRenderer.createPlayerSpawn(coords[0], coords[1], options.player);
            var ASCoords = game.gameMap.convertGridCoordsToAStarCoords([x - 1,y]);
            for(var row=0;row<3;row++){
                for(col=0;col<3;col++){
                    var astarX = (ASCoords[0]>>0) + col + row;
                    var astarY = (ASCoords[1]>>0) - row + col;
                    game.gameMap.grid.pathGrid[astarX][astarY] = 1;
                }
            }
            break;
            
        case "corridor":
            this.graphics = game.gameRenderer.createCorridor(coords[0], coords[1], options.player);
            var ASCoords = game.gameMap.convertGridCoordsToAStarCoords([x,y]);
            //game.gameMap.grid.pathGrid[ASCoords[0]][ASCoords[1]] = 1;
            break;
        case "extractor":
            this.graphics = game.gameRenderer.createExtractor(coords[0], coords[1], orientation, options.player);
            //var ASCoords = game.gameMap.convertGridCoordsToAStarCoords([x,y]);
            //console.log(ASCoords);
            //for(var col = -1; col < 1; col++){
            //    for(var row = -1; row < 1; row++){
            //        game.gameMap.grid.pathGrid[(ASCoords[0] >> 0) + (col*2)][(ASCoords[1] >> 0) + (row*2)] = 1;
            //    }
            //}
            break;
        case "generator":
            this.graphics = game.gameRenderer.createGenerator(coords[0], coords[1], orientation, options.player);
            //var ASCoords = game.gameMap.convertGridCoordsToAStarCoords([x,y]);
            //for(var col = -1; col < 1; col++){
            //    for(var row = -1; row < 1; row++){
            //        game.gameMap.grid.pathGrid[ASCoords[0]+(col*2)][ASCoords[1]+(row*2)] = 1;
            //    }
            //}
            break;
        case "biodome":
            this.graphics = game.gameRenderer.createGarden(coords[0], coords[1], orientation, options.player);
            //var ASCoords = game.gameMap.convertGridCoordsToAStarCoords([x,y]);
            //for(var col = -1; col < 1; col++){
            //    for(var row = -1; row < 1; row++){
            //        game.gameMap.grid.pathGrid[(ASCoords[0] >> 0) + (col*2)][(ASCoords[1] >> 0) + (row*2)] = 1;
            //    }
            //}
            break;
        case "kitchen":
            this.graphics = game.gameRenderer.createKitchen(coords[0], coords[1], orientation, options.player);
            //var ASCoords = game.gameMap.convertGridCoordsToAStarCoords([x,y]);
            //for(var col = -1; col < 1; col++){
            //    for(var row = -1; row < 1; row++){
            //        game.gameMap.grid.pathGrid[ASCoords[0]+(col*2)][ASCoords[1]+(row*2)] = 1;
            //    }
            //}
            break;
        case "defenceArea":
            this.graphics = game.gameRenderer.createKitchen(coords[0], coords[1], orientation, options.player);
            //var ASCoords = game.gameMap.convertGridCoordsToAStarCoords([x,y]);
            //for(var col = -1; col < 1; col++){
            //    for(var row = -1; row < 1; row++){
            //        game.gameMap.grid.pathGrid[ASCoords[0]+(col*2)][ASCoords[1]+(row*2)] = 1;
            //    }
            //}
            break;
    }

    if(this.underConstruct){
        this.graphics.alpha = 0.7;
    }
}
gamestructure.prototype.construct = function(){

}
gamestructure.prototype.concelConstruct = function(){

}
gamestructure.prototype.product = function(){

}
gamestructure.prototype.defend = function(){

}
gamestructure.prototype.search = function(){

}
gamestructure.prototype.destroy = function(player){

}